#include <bits/stdc++.h>

using namespace std;

const int MAXN = 1e5+10;

int h[MAXN],cnt,n,f[MAXN];

struct edge{int v,w,nxt;}e[MAXN<<1];

void link(int x,int y,int w){e[++cnt] = (edge){y,w,h[x]};h[x] = cnt;}

void dfs(int x,int p){
	for(int i = h[x];i;i = e[i].nxt){
		int y = e[i].v; if(y == p) continue;
		dfs(y,x); if(e[i].w == 2) f[x] += max(f[y],1);else f[x] += f[y];
	}
}

int main (){
	scanf("%d",&n);for(int i = 1;i < n;i++) {int x,y,w;scanf("%d %d %d",&x,&y,&w);link(x,y,w);link(y,x,w);}
	dfs(1,0);
	printf("%d\n",f[1]); return 0;
}
